﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="EN_OrgYldAndmed_response", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENOrgYldAndmedResponse))]
    public class ENOrgYldAndmedResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IENOrgYldAndmedResponse clazz;
        
        public ENOrgYldAndmedResponseSerializer(IENOrgYldAndmedResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("org_array");
            if (clazz.OrgArray!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>EN_OrgYldAndmed_response>org_array>org", "http://producers.ehr.xtee.riik.ee/producer/ehr", clazz.OrgArray.Count);
                for (int x = 0; ((clazz.OrgArray != null) 
                            && (x < clazz.OrgArray.Count)); x = (x + 1)) {
                    if (clazz.OrgArray[x]!=null) {
                        Writer.WriteStartElement("org");
                        global::Xtee.Core.SerializationMetadata metaOrgArray = this.GetMetaData(clazz.OrgArray[x]);
                        Writer.WriteTypeAttribute(metaOrgArray.TypeQualifiedName.Namespace, metaOrgArray.TypeQualifiedName.Name);
                        metaOrgArray.NewSerializer(clazz.OrgArray[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OrgArray");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="org_array") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_OrgYldAndmed_response>org_array");
                }
                clazz.OrgArray = new System.Collections.Generic.List<ENOrgYldAndmedResponse.IOrgArrayType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("org_array");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "org")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>EN_OrgYldAndmed_response>org_array>org");
                        }
                        global::Xtee.Core.SerializationMetadata metaOrgArray = this.GetMetaData<ENOrgYldAndmedResponse.IOrgArrayType>(Reader, ">>>EN_OrgYldAndmed_response>org_array>org", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                        ENOrgYldAndmedResponse.IOrgArrayType item = metaOrgArray.NewEntity<ENOrgYldAndmedResponse.IOrgArrayType>();
                        clazz.OrgArray.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("org");
                            metaOrgArray.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>EN_OrgYldAndmed_response>org_array", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>EN_OrgYldAndmed_response>org_array>org", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENOrgYldAndmedResponse.OrgArrayType))]
        public class OrgArrayTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected ENOrgYldAndmedResponse.IOrgArrayType clazz;
            
            public OrgArrayTypeSerializer(ENOrgYldAndmedResponse.IOrgArrayType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                if (clazz.OrgEhakkood!=null) {
                    Writer.WriteStartElement("org_ehakkood");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OrgEhakkood))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.OrgRegKood!=null) {
                    Writer.WriteStartElement("org_reg_kood");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OrgRegKood))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.OrgEPost!=null) {
                    Writer.WriteStartElement("org_e_post");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OrgEPost))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.OrgFaks!=null) {
                    Writer.WriteStartElement("org_faks");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OrgFaks))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.OrgTelefon!=null) {
                    Writer.WriteStartElement("org_telefon");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OrgTelefon))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.OrgPostiaadresss!=null) {
                    Writer.WriteStartElement("org_postiaadresss");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OrgPostiaadresss))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.OrgNimetus!=null) {
                    Writer.WriteStartElement("org_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OrgNimetus))).ToString());
                    Writer.WriteEndElement();
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="org_ehakkood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OrgYldAndmed_response>org_array>org>org_ehakkood");
                    }
                    clazz.OrgEhakkood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("org_ehakkood")).Value;
                }
                if (Reader.LocalName=="org_reg_kood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OrgYldAndmed_response>org_array>org>org_reg_kood");
                    }
                    clazz.OrgRegKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("org_reg_kood")).Value;
                }
                if (Reader.LocalName=="org_e_post") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OrgYldAndmed_response>org_array>org>org_e_post");
                    }
                    clazz.OrgEPost = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("org_e_post")).Value;
                }
                if (Reader.LocalName=="org_faks") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OrgYldAndmed_response>org_array>org>org_faks");
                    }
                    clazz.OrgFaks = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("org_faks")).Value;
                }
                if (Reader.LocalName=="org_telefon") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OrgYldAndmed_response>org_array>org>org_telefon");
                    }
                    clazz.OrgTelefon = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("org_telefon")).Value;
                }
                if (Reader.LocalName=="org_postiaadresss") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OrgYldAndmed_response>org_array>org>org_postiaadresss");
                    }
                    clazz.OrgPostiaadresss = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("org_postiaadresss")).Value;
                }
                if (Reader.LocalName=="org_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OrgYldAndmed_response>org_array>org>org_nimetus");
                    }
                    clazz.OrgNimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("org_nimetus")).Value;
                }
            }
        }
    }
}
